// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// String utility functions

#ifndef UTIL_STRING_H
#define UTIL_STRING_H

#include "util/Common.h"
#include <cstdarg>
#include <string>
#include <vector>
#include <cwchar>

class String {
private:
	String();
	~String();

public:	
	static char *dup(const char *s);
	static void destroy(char *s);

	static wchar_t *wdup(const wchar_t *s);
	static void wdestroy(wchar_t *s);

	static std::wstring asWString(int32_t i);

	static int wsToInt(const wchar_t *s);

	static bool endsWith(const std::string &s, const std::string &suffix);

	static std::string toUtf8(const std::wstring &ws);
	static std::wstring fromUtf8(const std::string &s);

	static std::string replace(const std::string &src, const std::string &target, const std::string &replacement);
	static void tokenize(const std::string& str,
			std::vector<std::string>& tokens,
			const std::string& delimiters = " ");
	static void split(const std::string &str, std::vector<std::string> &tokens, const std::string &sep);
	static void join(const std::vector<std::string> &tokens, std::string &str, const std::string &sep);
};

#endif
